class Solution {
public:
    ListNode* reverseList(ListNode* head) {
        
        ListNode* pre;
        ListNode* last;
        ListNode* tmp;

        last = nullptr;
        if (head == nullptr)return head;
        pre = head;
        while (pre->next != nullptr)
        {
            
                tmp = pre->next;
                pre->next = last;
                last=pre;
                pre = pre->next;
        }
        head = pre;
        
        return head;
    }
};
